jQuery(document).ready(function() {
	// set initial display state of offer form
	if(jQuery('#tp_offer_flag').attr('checked')) {
		jQuery('#tp_form').show();
	}
	// bind choice group (table) actions
	jQuery('.tp-choice-group').click(focusChoiceGroup);
	// bind offer form checkbox action
	jQuery('#tp_offer_flag').click(function() {
		jQuery('#tp_form').toggle();
	});
	// focus groups for selected radios
	jQuery('.tp-choice-group input:checked').each(function() {
		focusChoiceGroup.call(jQuery(this).parents('.tp-choice-group:first'));
	});
});

function focusChoiceGroup() {
	var group = jQuery(this);
	var radio = group.find(".tp-radio-group input");
	var section = group.parents('.tp-section:first');
	// set radio to checked
	radio.attr('checked', 'checked');
	// disable all groups in section
	section.find('.tp-choice-group').removeClass('tp-focused');
	section.find('label').addClass('tp-disabled');
	section.find('input[type="text"], select, textarea').attr('disabled', 'disabled');
	//enable controls in this group
	group.addClass('tp-focused');
	group.find('input[type="text"], select, textarea').removeAttr('disabled');
	group.find('label').removeClass('tp-disabled');
}